package com.jt.controller;

import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {

    @Autowired
    private ItemCatService itemCatService;

    /**
     * 需求: 查询三级商品分类信息
     * URL地址: /itemCat/findItemCatList/{level}
     * 参数:    level  1/2/3
     * 返回值:  SysResult(三级菜单)
     */
    @GetMapping("/findItemCatList/{level}")
    public SysResult findItemCatList(@PathVariable Integer level){
        List<ItemCat> catList = itemCatService.findItemCatList(level);
        return SysResult.success(catList);
    }

    /**
     * 业务需求:
     *   实现商品分类新增操作
     *   url地址: /itemCat/saveItemCat
     *   参数:    JSON串
     *   提交方式: post
     *   返回值:  SysResult对象
     */
    @PostMapping("/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){

        itemCatService.saveItemCat(itemCat);
        return SysResult.success();
    }

    /**
     * 业务说明: 删除商品分类数据
     * URL地址: /itemCat/deleteItemCat
     * 参数:    id/level
     * 返回值:  SysResult对象
     */
    @DeleteMapping("/deleteItemCat")
    public SysResult deleteItemCat(ItemCat itemCat){

        itemCatService.deleteItemCat(itemCat);
        return SysResult.success();
    }


}
